use druid::widget::{Button, Flex, Label};
use druid::{AppLauncher, LocalizedString, Color,PlatformError, Widget, WidgetExt, WindowDesc,Size};
use druid::widget::prelude::*;

const LIGHTER_GREY: Color = Color::grey8(0xbb);


/*测试环境  windows 10  +msys2 +stable-x86_64-pc-windows-gnu */
fn main() -> Result<(), PlatformError> {
    let main_window = WindowDesc::new(ui_builder)
    .title("测试")
    .window_size(Size::new(1000.0, 500.0));
    let data = 0_u32;
    AppLauncher::with_window(main_window)
        .use_simple_logger()
        .launch(data)
}

fn ui_builder() -> impl Widget<u32> {
    // The label text will be computed dynamically based on the current locale and count
    //let text = LocalizedString::new("hello-counter").with_arg("count", |data: &u32, _env| (*data).into());
    let label = Label::new(|data: &u32, _env: &_| format!("当前计数: {}", data)).padding(5.0).center();
    let button = Button::new("自增")
        .on_click(|_ctx, data, _env| *data += 1)
        .padding(5.0);

    Flex::column().with_child(label).with_child(button).background(LIGHTER_GREY)
}